package com.homedo.microservice.open.service.gateway.manager.web.persistence.dao;

import com.homedo.common.dao.BaseDao;
import com.homedo.common.util.Detect;
import com.homedo.microservice.open.service.gateway.manager.web.bean.po.ServiceGateway;
import com.homedo.microservice.open.service.gateway.manager.web.persistence.mapper.IServiceGatewayMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.List;


/**
 * @author 作者 jgshun
 * @date 创建时间 2018年09月25日 17时10分10秒
 */
@Repository
public class ServiceGatewayDao extends BaseDao<ServiceGateway> {
    @Autowired
    private IServiceGatewayMapper serviceGatewayMapper;

    public List<ServiceGateway> getAllOrderBySort() {
        Example example = new Example(ServiceGateway.class);
        example.setOrderByClause(ServiceGateway.ORDER_SORT_ASC);

        return super.getListByExample(example);
    }

    public List<ServiceGateway> getListByName(String name, List<String> envs) {
        Example example = new Example(ServiceGateway.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo(ServiceGateway.FIELD_NAME, name);
        if (Detect.notEmpty(envs)) {
            criteria.andIn(ServiceGateway.FIELD_ENV, envs);
        }
        example.setOrderByClause(ServiceGateway.ORDER_SORT_ASC);

        return super.getListByExample(example);
    }
}
